vm = new Vue({
    el: '#app',  //选中整个main
    data: {
        newGoodsList: {},
        hotGoodsList: {},
        types: {},
        goodsName: ''
    },
    methods: {
        exitLogin:function(){
            axios.get("user/exitLogin").then(rs=>{
                sessionStorage.removeItem("user");
                sessionStorage.removeItem("showNum");
                sessionStorage.removeItem("typeId");
                layer.msg("退出登录成功！");
                location.href="index.html";
            });
        },
        //搜索，模糊查询
        search: function () {
            sessionStorage.setItem("typeId", 0);
            sessionStorage.setItem("goodsName", this.goodsName);
            sessionStorage.removeItem("goodsName");
            location.href = 'productList.html';
        },
        //搜索，模糊查询
        search: function () {
            sessionStorage.setItem("typeId", 0);
            sessionStorage.setItem("goodsName", this.goodsName);
            location.href = 'productList.html';
        },
        //列表转换
        toGoodsListByType: function (typeId) {
            sessionStorage.setItem("typeId", typeId);
            location.href = 'productList.html';
        },
        //获取商品列表
        getAllGoodsType: function () {
            axios.get('type/getAllGoodsType').then(rs => {
                this.types = rs.data.obj;
            });
        },
        getGoods: function () {
            axios.get("goods/getNewGoods").then(rs => {
                this.newGoodsList = rs.data.obj;
            })

            axios.get("goods/getHotGoods").then(rs => {
                this.hotGoodsList = rs.data.obj;
            })
        },
        //商品详情
        toDetail: function (goods, event) {
            // event.preventDefault();
            axios.put(`goods/updateLookById/${goods.id}/${goods.look}`).then(rs => {
                goods.look = goods.look + 1;
                layer.msg(rs.data.msg);
                sessionStorage.setItem('goods', JSON.stringify(goods));
                location.href = 'goodsDetail.html';
            }).catch(e => {
                layer.msg(e.message)
            });
        },
        getUserInfo: function () {
            axios.get('user/getUserInfo').then(rs => {
                let user = rs.data.obj;
                sessionStorage.setItem("user", JSON.stringify(user));
                sessionStorage.setItem("showNum", 5);
                sessionStorage.setItem("typeId", 0);
            }).catch(e => {
                layer.msg(e.message);
            }).finally(()=>{
                this.getGoods();
                this.getAllGoodsType();
            })
        }
    },
    mounted:function () {
        this.getUserInfo();
    },
});